<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 考场管理
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <!--                <el-select v-model="query.address" placeholder="地址" class="handle-select mr10">-->
        <!--                    <el-option key="1" label="广东省" value="广东省"></el-option>-->
        <!--                    <el-option key="2" label="湖南省" value="湖南省"></el-option>-->
        <!--                </el-select>-->
        <!--        <el-input v-model="subjectSearch" placeholder="课程名称" class="handle-input mr10"></el-input>-->
        <el-select v-model="searchParam.site" placeholder="请选择">
          <el-option
              v-for="item in sites"
              :value="item.name">
          </el-option>
        </el-select>
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
      </div>
      <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column label="教学楼">
          <template #default="scope">{{ scope.row.parentBuilding }}</template>
        </el-table-column>
        <el-table-column label="房间号" align="center">
          <template #default="scope">
            {{ scope.row.roomNum }}
          </template>
        </el-table-column>
        <el-table-column label="是否考场">
          <template #default="scope">
            <span v-if="scope.row.status == '1'">否</span>
            <span v-if="scope.row.status == '2'">是</span>
            <span v-if="scope.row.status == '4'">不可用</span>
          </template>
        </el-table-column>
        <el-table-column label="设置考场" fixed="right">
          <!--          <template #default="scope">{{ scope.row.examStatus }}</template>-->
          <template #default="scope">
            <el-switch
                v-model="tableData[scope.$index].buttonStatus"
                active-color="#13ce66"
                @change="changeStatus(scope.row)"
                inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 编辑弹出框 -->
    <!--    <el-dialog title="编辑" v-model="editVisible" width="30%">-->
    <!--      <el-form label-width="70px">-->
    <!--        <el-form-item label="用户名">-->
    <!--          <el-input v-model="form.name"></el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item label="地址">-->
    <!--          <el-input v-model="form.address"></el-input>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--      <template #footer>-->
    <!--        <span class="dialog-footer">-->
    <!--          <el-button @click="editVisible = false">取 消</el-button>-->
    <!--          <el-button type="primary" @click="saveEdit">确 定</el-button>-->
    <!--        </span>-->
    <!--      </template>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import {selectAllClassRoom,changeClassRoomStatus} from "../api";

export default {
  name: "ClassTable",
  data() {
    return {
      subjectName: '',
      tableData: [
        {
          id:0,
          parentBuilding: '',
          roomNum: '',
          status: '',
          buttonStatus:false,
        },
      ],
      switchStatus: true,
      subjectSearch: '',
      examStatus: '结束',
      sites: [
        {
          name: '第一教学楼',
        }, {
          name: '第二教学楼',
        }, {
          name: '实验室',
        }
      ],
      searchParam: {
        site: '第一教学楼',
        type: '',
      }
    }
  },
  methods: {
    handleSearch() {
      selectAllClassRoom({site: this.searchParam.site}).then(res => {
        if (res.code === '200') {
          this.tableData = res.data;
          for(let i=0;i<this.tableData.length;i++){
            if(this.tableData[i].status === '1'){
              this.tableData[i].buttonStatus = false;
            }else if(this.tableData[i].status === '2'){
              this.tableData[i].buttonStatus = true;
            }
          }
          this.$message.success(res.message);
        } else {
          this.$message(res.message);
        }
      })
    },
    saveEdit() {

    },
    changeStatus(row) {
      changeClassRoomStatus({id:row.id}).then(res => {
        if(res.code === '200'){
          // this.$message("成功");
          this.handleSearch();
        }
      })
    },
  },
  mounted() {
    this.handleSearch();
  }
}
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>